<?php
require_once('includes/config.php');
require_once('includes/functions/func.global.php');
require_once('includes/classes/class.template_engine.php');
require_once('includes/lang/lang_'.$config['lang'].'.php');

// Connect to database
db_connect($config);

// Retrieve stories from the database
$query = "SELECT story_id,story_time,story_digs,story_title,story_buries FROM ".$config['db']['pre']."stories WHERE story_time>'".(time()-43200)."' LIMIT 500";
$query_result = @mysql_query ($query) OR error(mysql_error(), __LINE__, __FILE__, 0, '', '');
while ($info = @mysql_fetch_array($query_result))
{
	$ago = round(((time()-$info['story_time'])/60));
	$digs = $info['story_digs'];
	$buries = $info['story_buries'];
	
	$rate = ($ago/$digs);
	
	if($buries > 5)
	{
		$rate = 99999;
	}

	mysql_query("UPDATE `".$config['db']['pre']."stories` SET `story_rating` = '".addslashes($rate)."' WHERE `story_id` =".$info['story_id']." LIMIT 1 ;");
}

mysql_query("UPDATE `".$config['db']['pre']."stories` SET `story_rating` = '99999' WHERE story_time>'".(time()-604800)."' AND story_time<'".(time()-432000)."'");

echo 'ran succesfully';
?>